 var id = getvl("id");
$(function(){
        if(id != '') {
        	slelectnot();
        }else{
           // alert("请传入商品id");	
         }
});
var userid="";
var currentPage=1;
function chaxunwodezhuji2(){
	$(document).ready(function() {
		init(currentPage);
	});
	
	function init(pageNo) {
		     if(uuuuid!=''){
		$.ajax({
		url: urlcore + "/api/myFoot/selectPage2?current="+pageNo+"&userId="+uuuuid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				var wodezhuji="";
				$.each(data.data.list, function(y,w) {
					wodezhuji+='<dl>'+
'		<dt>'+
'	<a id="mdianhua" href="7.0.0goods_detail.html?id='+w.goods.id+'"><img onerror="errorImg(this)" src="'+w.goods.coverUrl+'"/></a>'+
'		</dt>'+
'		<dd>'+
'			<h5>'+w.goods.goodsTitle+'</h5>'+
'			<h6>&yen;'+w.goods.tradePrice+'- &yen;'+w.goods.packPrice+'</h6>'+
'		</dd>'+
'	</dl>'+
'	<dl>';
					});
			   $("#wodezhuji").append(wodezhuji);
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
	 }else{
	 	//alert("未登录");
	 }
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}

 var mygoodsid="";
//查询是否收藏过
function shifoushouchang(){
	      if(uuuuid!=""){
		$.ajax({
		url: urlcore + "/api/goods/isCollection2?id="+id+"&userId="+uuuuid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if(data.success == true) {
				 var da=data.data;
				    if(da==null){
				   $("#shifoushouchangs").attr("src","images/detail_bottom04.png");
				    }else{
				    	if(da.status==1){
			 	 $("#shifoushouchangs").attr("src","images/detail_bottom05.png");
			 }else{
			 	$("#shifoushouchangs").attr("src","images/detail_bottom04.png");
			 }
				    }
			}else{
				$("#shifoushouchangs").attr("src","images/detail_bottom04.png");
			}
			
			
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
	 }
}








function shouchang(){
	if(uuuuid!=''){
	var imgs=$("#shifoushouchangs").attr("src");
	if(imgs=="images/detail_bottom04.png"){
      $("#shifoushouchangs").attr("src","images/detail_bottom04.png");
         $.ajax({
		url: urlcore + "/api/myCollection/update", 
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			userId:uuuuid,
			goodsId:id,
			status:2
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				slelectnot();
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
	}else if(imgs=="images/detail_bottom05.png"){
		  $("#shifoushouchangs").attr("src","images/detail_bottom05.png");
         $.ajax({
		url: urlcore + "/api/myCollection/update", //userid
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			userId:uuuuid,
			goodsId:id,
			status:1
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
	}else{
		  $("#shifoushouchangs").attr("src","images/detail_bottom04.png");
	}
	}
}

function slelectnot(){
		 $("#slideBox").html("");
		 $("#shangpingxiangqing").html("");
		 $("#jiarujinghuoche").attr("href","7.2.0goods_guige.html?id="+id);
		$.ajax({
        url: urlcore + "/api/goods/particulars2?id="+id,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					  $('#img_details').html("");
				    var da=data.data;
				    	   	     var shangpingxiangqing="";
				      if(da.goods.goods_simple!=null && da.goods.goods_simple!=""){
				          shangpingxiangqing+='<center><h5 class="miaoshu">描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述</h5></center>';
				           shangpingxiangqing+='<h6>'+da.goods.goods_simple+'</h6>';
				        }
				    var yanshe="无";
				    var chicun="无";
				    var shuxing="无";
				      if(da.list!=null && da.list!=""){
				      	yanshe="";
				      	chicun="";
				      	shuxing="";
				      	var svu=0;
				      	  shangpingxiangqing+='<center><h3 class="miaoshu">参&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数</h3></center>';
				      	   $.each(da.list, function(s,n) {
				      	   	if(s==0){
				      	   		  yanshe+=n.colour.colourName;
				      	   		  chicun+=n.size.sizeName;
				      	   	}else{
				      	   		  yanshe+=","+n.colour.colourName;
				      	   		   chicun+=","+n.size.sizeName;
				      	   	}
				        svu++;
				              if(da.list.length==svu){
				              	       if(da.propertyList!=null && da.propertyList!=""){
				              	       	      	     	 $.each(da.propertyList, function(y,q) {
				         shuxing+="<h5>"+q.oneProperty+":&nbsp;&nbsp;&nbsp;"+q.twoProperty+'</h6>';
                          });
				              	       }
				              }
				      	   });
				      	           shangpingxiangqing+="<h6>颜色 :"+yanshe+"</br>";
				         shangpingxiangqing+="尺码 :"+chicun+"</h3>";
				         shangpingxiangqing+=shuxing;
				        }
				   $("#shangpingxiangqing").append(shangpingxiangqing);
				    //分类按钮
				    
		$("#fenlei").attr("href","6.2.0dianpu_fenlei.html?id="+da.shopinfo.id);
		var goodsimg='<div><img style="width: 100%;"    src="'+da.goods.cover_url+'" /></div><br>';
				       var headImg=da.goods.goods_url;
				                     var imgStr1='<div id="slideBox" class="slideBox">'+
		      '<div class="bd" id="lunbo">'+
			'<ul>';
			 imgStr1 +='<li><img  data-preview-src="" data-preview-group="1"  src="'+da.goods.cover_url+'" /></li>';
					 if(headImg != null && headImg != '') {
						var imgarr1 = headImg.split("***");
						$.each(imgarr1, function(index, value) {
						 imgStr1 +='<li><img  data-preview-src="" data-preview-group="1" src="'+value+'" /></li>';
						 goodsimg+='<div><img   style="width: 100%;" src="'+value+'"></div><br>';
              //alert(goodsimg)
            
						});
					}
					 			imgStr1 +='</ul>'+
'		</div>'+
'		<div class="hd">'+
'			<ul></ul>'+
'		</div>'+
'	</div>';
						$("#lunbotu").append(imgStr1);
						  $("#goodsimg").append(goodsimg);
					 
					 
					 	$(function(){
							TouchSlide({
		slideCell:"#slideBox",
		titCell:".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
		mainCell:".bd ul", 
		effect:"leftLoop", 
		autoPage:true,//自动分页
		autoPlay:true //自动播放
	});
						}); 
 
            
               var d1 = new Date().getTime(); 
               var d2=new Date(da.goods.upt_datetime).getTime();
  var dateds=1;
             if(parseInt((d1 - d2))<8640000){  //今天
             	   if(parseInt((d1 - d2))<3600000){
             	   	    dateds=parseInt(((d1 - d2)/(1000*60)))+"分前更新"; 
             	   }else{
             	   	    dateds="今天"+new Date(da.goods.upt_datetime).pattern("hh:mm");  
             	   }
             	
             	
             }else  if(parseInt((d1 - d2))<172800000){
             	 dateds="昨天"+new Date(da.goods.upt_datetime).pattern("hh:mm"); 
             }else{
             	 dateds=new Date(da.goods.upt_datetime).pattern("MM-dd"); 
             }
				    var jianjie='<h2>'+da.goods.goods_title+'</h2>'+
	'<ul class="clearfix">'+
		'<li>'+
			'<span>1-'+da.goods.trade_number+'件</span>'+
			'<h5>&yen;'+da.goods.trade_price+'</h5>';
			
			 if(dateds==0){
			 	jianjie+='<em>1分钟前更新</em>';
			 }else{
			 	jianjie+='<em>'+dateds+'分钟前更新</em>';
			 }
		jianjie+='</li>'+
		'<li>'+//&yen;'+da.goods.pack_price+''+da.goods.trade_number+'-'+da.goods.get_number+'件
			'<span>&nbsp;</span>'+
			'<span>&nbsp;</span>'+
			'<h5>&nbsp;</h5>'+
			'<em>'+da.goods.look_time+'次浏览</em>'+
		'</li>'+
		'<li>'+
			'<span>'+da.goods.pack_number+'件以上</span>'+
			'<h5>&yen;'+da.goods.pack_price+'</h5>'+
			'<em>已卖出'+da.goods.sale_num+'件</em>'+
		'</li>'+ 
	'</ul>';
	       $("#jianjie").append(jianjie);  //产品规格信息完结
          var dikou='<ul>'+
	'<li><img src="../images/di.png" />可用金币抵扣'+da.shopinfo.allGoldRate+'%</li>';
	     if(da.shopinfo.openGold==0){
	dikou+='<li><img src="../images/zeng.png" />每件最高赠送金币0个</li>';     	
	     }
	dikou+='<li><img src="../images/zeng.png" />每件最高赠送金币'+da.goods.gold_rate+'个</li>'+
		'<li><img src="../images/pi.png" />全店满'+da.shopinfo.mixNumber+'件可混批采购</li>'+
	    '</ul>';
           $("#dikou").append(dikou);  //抵扣优惠完结
  
           var pingjia='<div class="Pingjia_title">'+
		'<a href="../7.1.0goods_pingjia.html?id='+da.goods.id+'">'+da.commentList.length+'条评价</a>'+
	'</div>';
	         $.each(da.commentList,function(m,z){
	         	 var dar=new Date(z.gmt_datetime).pattern("yyyy-MM-dd hh:mm");
	         	  pingjia+='<div class="sell_pingjia_xinxi">'+
		'<div class="sell_pingjia_tu">'+
			'<img src="'+z.head_img+'" />'+
		'</div>'+
		'<div class="sell_pingjia_wenzi">'+
			'<div class="sell_pingjia_mz clearfix">'+
				'<h5>'+z.user_name+'</h5>'+
				'<div class="fr">';
				       for(var i=0;i<z.service_level;i++){
				       	pingjia+='<img src="../images/star.png" />';
				       }
					pingjia+='<i>4.0分</i>'+
				'</div>'+
			'</div>'+
			'<span>'+dar+'</span>'+
			'<p>'+z.comment_content+'</p>'+
		'</div>'+
	'</div>';
	             return false;
	         });
	
                   $("#pingjia").append(pingjia);  //评价完结
                   var dianpu=
                   '<dl>'+
		'<a href="#" onclick="quanbushangping('+da.shopinfo.id+')">'+
			'<dt>'+
				'<img src="'+da.shopinfo.headImg+'" />'+
			'</dt>'+
			'<dd>'+
				'<h5>'+da.shopinfo.storeName+'</h5>'+
				'<h6>全部商品共'+da.size+'件</h6>'+
				'<span>'+da.shopinfo.address+'</span>'+
			'</dd>'+
		'</a>'+
	'</dl>'+
	'<div class="Dianpu_quanbu">'+
		'<a href="#"  onclick="quanbushangping('+da.shopinfo.id+')">全部商品<span>('+da.size+')</span></a>'+
		'<a href="tel:'+da.shopinfo.phone+'">联系店家</a>'+
	'</div>';
	      $('#dianpu').append(dianpu);   //店铺信息
                   //商品详情图片还没添加 轮播图还没做
              shifoushouchang();     
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				alert("error");
			}
		});
        }

//引入微信js


//xiugai



function quanbushangping(shopid){
	window.location.href="../6.0.0dianpu.html?id="+shopid;
}

function xiugai(te){

	window.location.href="24.2.0fabu_goods.html?id="+id;
	//$(te).attr("href",");
}


function chongxinfabu(){
	if(id!=''){
	
	    $.ajax({
	    	url: urlcore + "/api/goods/update",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"id":id,
			"status":0
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				alert("成功,后台审批");
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}

	   });
	}
}


function xiajiagoods(){
	
	if(id!=''){
	
	    $.ajax({
	    	url: urlcore + "/api/goods/update",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"id":id,
			"status":2
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				alert("下架成功");
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}

	   });
	}

}
